/**
*      author: Y_Yao
*      created: 2025-04-21 14:25:28
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 7;
int n;
unordered_map<int,int> mp;

void solve()
{
    vector<int> a;
    cin >> n;

    for(int j = 1;j < 32;j++)
    {
        int x = 1 << j;
        if(x > n) break;
        a.push_back(1 << j);

    }
    for(int i = n;i >= 1;i--)
    {
        int tail = a[a.size() - 1];
        if(mp.count(i))
        {
            if(i == tail)
            {
                a.pop_back();
            }
            continue;
        }
        if(i == tail)
        {
            mp[i] = i - 1;
            mp[i - 1] = i;
            a.pop_back();
            continue;
        }
        int diff = i - tail;
        mp[i] = tail - diff - 1;
        mp[tail - diff - 1] = i;

    }
    for(int i = 1;i <= n;i++)
    {
        int x;
        cin >> x;
        cout << mp[x] << " ";
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}